package com.ke.rule.base;

import com.ke.rule.base.FuncUnitDecider.Consequences;

/**
 * FuncUnit（Validator/Processor/Dispatcher）匹配规则集的事实（确定执行哪些FuncUnit的条件左值）
 * 
 * @author guyu
 *
 */
public class MatchingRulesFact {
  private MethodStepType stepType;          // 归属步骤
  private String entityName;                // 遍历中的当前实体名称，可能是根，也可能是子孙
  private Object value;

  // 决策结果
  private Consequences consequences;
  
  /**
   * constructor
   * @param stepType    方法中的当前步骤类型
   * @param entityName  实体名称
   */
  public MatchingRulesFact(MethodStepType stepType, String entityName, Object value) {
    super();
    this.stepType = stepType;
    this.entityName = entityName;
    this.value = value;
    this.consequences = new Consequences();
  }

  public MethodStepType getStepType() {
    return stepType;
  }

  public void setStepType(MethodStepType stepType) {
    this.stepType = stepType;
  }

  public String getEntityName() {
    return entityName;
  }

  public void setEntityName(String entityName) {
    this.entityName = entityName;
  }

  public Object getValue() {
    return value;
  }

  public void setValue(Object value) {
    this.value = value;
  }

  public Consequences getConsequences() {
    return consequences;
  }
  
  /**
   * 向功能部件的执行链上追加新的节点
   * @param funcUnitSpec 符合正则表达式的规格文本
   */
  public void attach(String funcUnitSpec) {
    this.consequences.include(funcUnitSpec);
  }
  
  /**
   * 从Validator或Processor的链上排除已有节点
   * @param simpleNames 以逗号分割的需要排除的类名
   */
  public void detach(String simpleNames) {
    this.consequences.exclude(simpleNames);
  }

  @Override
  public String toString() {
    return "MatchingRulesFact{" +
            "stepType=" + stepType +
            ", entityName='" + entityName + '\'' +
            ", consequences=" + consequences +
            '}';
  }
}
